package com.aigou.controller;

import java.io.IOException;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.aigou.pojo.Result;
import com.aigou.utils.UploadImageUtil;

@RestController
public class UploadController {
	
	@PostMapping("/upload")
	public Result upload(MultipartFile myfile) throws IOException {
		
		System.out.println(myfile.getOriginalFilename());
		// 存储到本地，返回可访问路径  “localhost:8081/xxxx.jpg”
		// myfile.transferTo(new File("d:/"));
		
		// 将接受的图片内容上传图片服务器
		// 图片服务器会返回可访问路径
		
		// 提供客户端，上传方法，返回路径
		String url = UploadImageUtil.getImageUrl(myfile.getInputStream(), myfile.getOriginalFilename());
		
		Result result = new Result();
		result.setData(url);
		return result;
	}

}
